package cn.stylefeng.guns.modular.hx.storage.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.hx.storage.entity.HxErrorPick;
import cn.stylefeng.guns.modular.hx.storage.mapper.HxErrorPickMapper;
import cn.stylefeng.guns.modular.hx.storage.model.params.HxErrorPickParam;
import cn.stylefeng.guns.modular.hx.storage.model.result.HxErrorPickResult;
import  cn.stylefeng.guns.modular.hx.storage.service.HxErrorPickService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 错漏拣 服务实现类
 * </p>
 *
 * @author lww
 * @since 2023-11-04
 */
@Service
public class HxErrorPickServiceImpl extends ServiceImpl<HxErrorPickMapper, HxErrorPick> implements HxErrorPickService {

    @Override
    public void add(HxErrorPickParam param){
        HxErrorPick entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(HxErrorPickParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(HxErrorPickParam param){
        HxErrorPick oldEntity = getOldEntity(param);
        HxErrorPick newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public HxErrorPickResult findBySpec(HxErrorPickParam param){
        return null;
    }

    @Override
    public List<HxErrorPickResult> findListBySpec(HxErrorPickParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(HxErrorPickParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findPageBySpec1(HxErrorPickParam param, String condition) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.DetailsList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findAppDaichuliPageBySpec(HxErrorPickParam hxErrorPickParam) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findAppDaichuliPageBySpec(pageContext, hxErrorPickParam);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public HxErrorPickResult checkyw(HxErrorPickParam checkyw) {
        return this.baseMapper.checkyw(checkyw);
    }

    private Serializable getKey(HxErrorPickParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private HxErrorPick getOldEntity(HxErrorPickParam param) {
        return this.getById(getKey(param));
    }

    private HxErrorPick getEntity(HxErrorPickParam param) {
        HxErrorPick entity = new HxErrorPick();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
